import { Command } from '../../../utils/commandManager';
import TypeScriptServiceClientHost from '../../../typeScriptServiceClientHost';
import { Lazy } from '../../../utils/lazy';
import { nulToken } from '../../../utils/cancellation';
import * as vscode from 'vscode';


export class 项目迁移命令_ implements Command {
    public static readonly Id = 'ctsscript.项目迁移命令_';
    public readonly ID = 项目迁移命令_.Id;
    constructor(private client: Lazy<TypeScriptServiceClientHost>) { }
    public async execute() {
        vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: "正在转换..." }, () => this.执行());
    }
    public async 执行() {
        const arg = { file: this.client.value.serviceClient.toOpenedFilePath(vscode.window.activeTextEditor!.document) };
        const 结果 = await this.client.value.serviceClient.execute("convertCts", arg, nulToken);
        if (结果 && 结果.type === "response" && 结果.body) {
            const { 成功, 消息 } = 结果.body;
            if (成功) {
                vscode.window.showInformationMessage(消息);
                this.client.value.serviceClient.logger.info(消息);
            }
            else {
                vscode.window.showErrorMessage<vscode.MessageItem>(消息, { title: "转换失败", isCloseAffordance: true });
            }
        }
        else {
            vscode.window.showErrorMessage<vscode.MessageItem>("转换失败！", { title: "转换失败", isCloseAffordance: true });
        }
    }
}